#include<iostream>
const int N = 1e6 + 10;
int e[N],pre[N],ne[N], mp[N], h, id, n;
using namespace std;
bool s[N];
int main()
{
	cin >> n;
	id++;
	e[id] = 1;
	pre[id] = h;
	ne[h] = id;
	for (int i = 2; i <= n; i++)
	{
		int m, p;
		cin >> m >> p;
		id++;
		e[id] = i;
		mp[i] = id;
		if (p == 0)
		{
			pre[id] = pre[m];
			ne[id] = ne[pre[m]];
			ne[pre[m]] = id;
			pre[m] = id;
		}
		else if (p == 1)
		{
			pre[id] = m;
			ne[id] = ne[m];
			pre[ne[m]] = id;
			ne[m] = id;
		}
	}
		int M; cin >> M;
		while (M--)
		{
			int x; cin >> x;
			if (s[x] == true) continue;
			ne[pre[x]] = ne[x];
			pre[ne[x]] = pre[x];
			mp[x] = 0;
			s[x] = true;
		}
		for (int i = ne[h]; i != 0; i = ne[i])
		{
			cout << e[i] << ' ';
		}
		cout << endl;
	return 0;
}